<?php
/**
 * Author：ghostsf
 * Blog：www.ghostsf.com
 * Date: 2016/6/16
 */

namespace app\admin\controller;
use app\admin\model\Classes;
use app\admin\model\Classroom;
use app\admin\model\Teacher;
use app\admin\model\Campus;
use app\admin\model\Course;
use app\admin\validate\ClassValidate;
use think\Db;
/**
 * 班级
 * Class ClassesController
 * Author ghostsf
 * Blog www.ghostsf.com
 * @package app\admin\controller
 */
class DuanxinController extends CommonController
{
    /**
     * 获得数据
     * Author mww
     */
    public function getDatas()
    {
        $rows = $_POST['rows'];
        $page = $_POST['page'];
        $path = $this->getDataByCampusid($_POST);
        $sucai = Db::table("ew_duanxin")
            ->where($path)->where('id','<','13')
            ->limit($rows * ($page - 1), $rows)->select();
        $total = Db::table("ew_duanxin")
            ->where($path)->where('id','<','13')->count();
        $data['total'] = $total;
        $data['rows'] = $sucai;
        return json_encode($data);
    }

    public function edit()
    {
        $id = input('id', '');
        $data = Db::table("ew_duanxin")
            ->where('id',$id)->find();
        $this->assign("data", $data);
        return $this->fetch("duanxin/update");
    }
    public function update()
    {
        $id = $_POST['id'];
        $content = trim($_POST['content'],' ');
        if($content == ''){
            $returnData['status'] = 0;
            $returnData['msg'] = "模板内容不能为空";
            return json_encode($returnData);
        }
        $res = Db::table("ew_duanxin")->where('id',$id)
            ->update(['content'=>$content]);
        if($res){
            $returnData['status'] = 200;
            $returnData['msg'] = "操作成功";
            return json_encode($returnData);
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "修改失败";
            return json_encode($returnData);
        }

    }
    //=========配置前台的算力产品================================================
    public function edit_home()
    {
        $id = input('id', '');
        $data = Db::table("ew_home")
            ->where('id',$id)->find();
        $this->assign("data", $data);
        return $this->fetch("duanxin/update_home");
    }
    public function update_home()
    {
        $id = $_POST['id'];
        foreach ($_POST as $key => $value) {
            $value = trim($value,' ');
            if($value == ""){
                return json_encode(['status'=>0,'msg'=>'有未填项']);
            }
        }
        $res = Db::table("ew_home")->where('id',$id)
            ->update($_POST);
        if($res){
            $pp = Db::table("ew_home")->select();
            $returnData['status'] = 200;
            $returnData['msg'] = "操作成功";
            $returnData['homesuanli'] = $pp;
            return json_encode($returnData);
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "修改失败";
            return json_encode($returnData);
        }

    }

}